package com.foodie.proxy.dynamicproxy;

import com.foodie.proxy.proxycase.IRentHouse;
import com.foodie.proxy.proxycase.RentHouse;
import com.foodie.proxy.proxycase.RentHouseImpl;
import org.junit.Test;

public class TestClass {
    /**
     * 测试代理工厂类JDK动态代理
     */
    @Test
    public void testProxyFactory() {
        System.out.println("测试代理工厂类JDK动态代理");
        IRentHouse rentHouse = new RentHouseImpl();
        IRentHouse rentHouseProxy = (IRentHouse) ProxyFactory.getInstance().getJDKProxy(rentHouse);
        rentHouseProxy.rentHouse();
    }

    /**
     * 测试代理工厂类Cglib动态代理(委托对象实现接口)
     */
    @Test
    public void testProxyFactory1() {
        System.out.println("测试代理工厂类Cglib动态代理(委托对象实现接口)");
        RentHouseImpl rentHouse = new RentHouseImpl();
        IRentHouse rentHouseProxy = (IRentHouse) ProxyFactory.getInstance().getCglibProxy(rentHouse);
        rentHouseProxy.rentHouse();
    }

    /**
     * 测试代理工厂类Cglib动态代理(委托对象不实现接口)
     */
    @Test
    public void testProxyFactory2() {
        System.out.println("测试代理工厂类Cglib动态代理(委托对象不实现接口)");
        RentHouse rentHouse = new RentHouse();
        RentHouse rentHouseProxy = (RentHouse) ProxyFactory.getInstance().getCglibProxy(rentHouse);
        rentHouseProxy.rentHouse();
    }


}
